package com.rui.prototype.model;

import lombok.Data;

/**
 * 浅克隆
 */
@Data
public class ShallowClazz implements Cloneable {

    private String name;
    private Student student;

    public static void main(String[] args) throws Exception {
        ShallowClazz shallowClazz1 = new ShallowClazz();
        shallowClazz1.setName("高三一班");
        Student stu1 = new Student("张三", "男", 18);
        shallowClazz1.setStudent(stu1);
        // ShallowClazz(name=高三一班, student=Student(name=张三, sex=男, age=18))
        System.out.println(shallowClazz1);

        ShallowClazz shallowClazz2 = (ShallowClazz) shallowClazz1.clone();
        Student stu2 = shallowClazz2.getStudent();
        stu2.setName("李四");
        // ShallowClazz(name=高三一班, student=Student(name=李四, sex=男, age=18))
        System.out.println(shallowClazz1);
        // ShallowClazz(name=高三一班, student=Student(name=李四, sex=男, age=18))
        System.out.println(shallowClazz2);
    }

    @Override
    protected Object clone() throws CloneNotSupportedException {
        return super.clone();
    }
}